Skip to content

Conversation

@reakaleek
Copy link
Member

No description provided.

@reakaleek reakaleek requested a review from a team as a code owner November 14, 2025 15:58
@reakaleek reakaleek requested a review from Mpdreamz November 14, 2025 15:58
options.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
});

_ = builder.Services.AddOpenTelemetry().UseOtlpExporter();
Copy link
Contributor

@cotti cotti Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a new OTLP Exporter, breaking integration testing (and I'd assume live).

The reason it creates a new one is that an implicit default ElasticOpenTelemetryOptions has its SkipOtlpExporter set to false. Also, this starts a new OpenTelemetry service which is already defined in the beginning of ConfigureOpenTelemetry, is this wanted?

@cotti
Copy link
Contributor

cotti commented Nov 19, 2025

Suggestion for ConfigureOpenTelemetry (passes integration):

	public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
	{
		_ = builder.Logging.AddOpenTelemetry(logging =>
		{
			logging.IncludeFormattedMessage = true;
			logging.IncludeScopes = true;
		});

		var skipOtlpExporter = string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

		_ = builder.Services.AddElasticOpenTelemetry(new ElasticOpenTelemetryOptions { SkipOtlpExporter = skipOtlpExporter })
			.WithMetrics(metrics =>
			{
				_ = metrics.AddAspNetCoreInstrumentation()
					.AddHttpClientInstrumentation()
					.AddRuntimeInstrumentation()
					.AddMeter(TelemetryConstants.AssemblerSyncInstrumentationName);
			})
			.WithTracing(tracing =>
			{
				_ = tracing.AddSource(builder.Environment.ApplicationName)
					.AddSource(TelemetryConstants.AssemblerSyncInstrumentationName)
					.AddAspNetCoreInstrumentation(instrumentation =>
						// Exclude health check requests from tracing
						instrumentation.Filter = context =>
							!context.Request.Path.StartsWithSegments(HealthEndpointPath)
							&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
					)
					// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
					//.AddGrpcClientInstrumentation()
					.AddHttpClientInstrumentation();
			});

		if (!skipOtlpExporter)
		{
			// Configure delta temporality for Elasticsearch compatibility
			// See: https://www.elastic.co/docs/reference/opentelemetry/compatibility/limitations#histograms-in-delta-temporality-only
			_ = builder.Services.Configure<MetricReaderOptions>(options =>
			{
				options.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
			});
		}
		return builder;
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants